package com.guli.common.util;

import java.util.*;

/**
 * @author XiaoHua666
 * @date 2019/4/17
 */
public class CollectionUtils {

    public static void sortList(List list) {
        Collections.sort(list);
    }

    public static void main(String[] args) {
        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("cab");
        arrayList.add("cbd");
        arrayList.add("aab");
        arrayList.add("aac");
        sortList(arrayList);
        arrayList.forEach(System.out::println);
        Student s1 = new Student("jack", "18");
        Student s2 = new Student("aack", "18");
        ArrayList<Student> sList = new ArrayList<Student>();
        sList.add(s1);
        sList.add(s2);
    }

    public static void removeDuplicateWithOrder(List list) {
        Set set = new HashSet();
        List newList = new ArrayList();
        for(Iterator iter = list.iterator(); iter.hasNext(); ) {
            Object element = iter.next();
            if(set.add(element)) {
                newList.add(element);
            }
        }
        list.clear();
        list.addAll(newList);
        System.out.println(" remove duplicate " + list);
    }

    public static List removeDuplicate(List list) {
        HashSet h = new HashSet(list);
        list.clear();
        list.addAll(h);
        return list;
    }


}
